package com.brspace.qualitycontrol.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.brspace.qualitycontrol.entity.Leaveing;
import com.brspace.qualitycontrol.entity.Prospecting;
import com.brspace.qualitycontrol.entity.vo.ProspectQueryVo;
import com.brspace.qualitycontrol.entity.vo.ProspectingVo;
import com.brspace.qualitycontrol.service.ProspectingService;
import com.brspace.qualitycontrol.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author wangt
 * @Date 2021/4/12 13:48
 * @Version 1.0
 */
@Api(description = "四到场")
@CrossOrigin
@RestController
@RequestMapping("/admin/prospecting")
public class ProspectingController {
    @Resource
    private ProspectingService prospectingService;

    @ApiOperation("四到场信息录入")
    @PostMapping("add")
    public R add(@RequestBody Prospecting prospecting) {
        prospectingService.save(prospecting);
        return R.ok();
    }

    @ApiOperation("四到场信息修改")
    @PostMapping("update")
    public R update(@RequestBody Prospecting prospecting) {
        prospectingService.updateById(prospecting);
        return R.ok();
    }

    @ApiOperation("四到场信息展示")
    @GetMapping("findAll/{page}/{limit}")
    public R findAll(@ApiParam(value = "当前页码", required = true)
                     @PathVariable Long page,
                     @ApiParam(value = "每页记录数", required = true)
                     @PathVariable Long limit,
                     @ApiParam("查询对象")ProspectQueryVo prospectingVo) {
        Page<Prospecting> pageParam = new Page<>(page, limit);
        IPage<Prospecting> pageModel = prospectingService.stateList(pageParam, prospectingVo);
        List<Prospecting> records = pageModel.getRecords();
        long total = pageModel.getTotal();
        return R.ok().data("total", total).data("rows", records);

    }

    @ApiOperation("批后管理测试")
    @PostMapping("list/{page}/{limit}")
    public R list1(
            @ApiParam(value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(value = "每页记录数", required = true)
            @PathVariable Long limit,

            @ApiParam(value = "查询对象")
                    ProspectQueryVo prospectingVo) {
        return prospectingService.selectPage01(page, limit, prospectingVo);
    }
}
